/**
 * 
 */
package com.scpii.universal.struts.manage;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.doone.comm.paginaction.Pagination;
import com.scpii.universal.action.BaseAction;
import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.ShareDto;
import com.scpii.universal.hibernate.entity.ShareTab;
import com.scpii.universal.service.ShareManageService;
import com.scpii.universal.service.ShareService;
import com.scpii.universal.service.TypeService;

/**
 * universalWeb
 * 
 * @author weny 2012-7-9下午05:20:49
 */
@Controller
@Scope("prototype")
public class ShareAction extends BaseAction {
	/**
	 * serialVersionUID
	 */
	private static final long serialVersionUID = 4629317011625914415L;
	@Resource
	private ShareManageService shareManageService;
	@Resource
	private TypeService typeService;
	@Resource
	private ShareService shareService;

	private Pagination page = new Pagination();

	private List<ShareDto> shareList;

	private ShareDto shareInfo;
	// 查询条件
	private ShareDto condition;
	// 分享类型
	private Map<Integer, String> typeTabList;

	// 分享列表页
	public String getSharePage() {
		// modify by zhangqiang 20120725
		// UserInfoDto userInfoDto=(UserInfoDto)
		// session.getAttribute("userInfoDto");
		if (condition == null) {
			condition = new ShareDto();
		}
		condition.setIntAppId(getUserInfo().getAppId());
		typeTabList = typeService
				.getTypeListByParentId(GenericConstants.SHARE_TYPE_ID);
		request.setAttribute("typeTabList", typeTabList);
		

			// 获取返回信息的条数
			Integer recordCount = shareManageService.getShareRecode(condition);

			if (getSelectPerPage("page") == -1) {
				page.setPageRecord(GenericConstants.PAGE_NO);
			} else {
				page.setPageRecord(getSelectPerPage("page"));
			}
			// 判断是否是第一次查询
			if (getQueryFlag("page") == -1) {
				page.setTotalRecord(recordCount);
			} else {
				page.setTotalRecord(getQueryFlag("page"));
			}
			setPageParameters(page, "page");
			// 获取页面返回list
			shareList = shareManageService.getShareListPage(condition,
					page.getCurrentPage(), page.getPageStart(),
					page.getPageRecord());
		
			for(ShareDto shareDto:shareList){
				shareDto.setVarTypeName(typeTabList.get((int)shareDto.getIntShareType()));
			}
			
		return SUCCESS;
	}

	/**
	 * 获取分享信息
	 * 
	 * @return
	 * @author weny 2012-7-13上午10:00:26
	 */
	public String getShare() {
		String intShare = request.getParameter("intShare");
		shareInfo = shareManageService.getShareInfo(Integer.valueOf(intShare));
		return SUCCESS;
	}

	/**
	 * 删除分享信息
	 * 
	 * @return
	 * @author weny 2012-7-19下午02:37:56
	 */
	public String delShare() {
		String intShare = request.getParameter("intShare");
		ShareTab shareTab = shareService.get(Integer.valueOf(intShare));
		shareTab.setIntDeleteSign(GenericConstants.DELETE_SIGN_DELETED);
		shareService.update(shareTab);
		return SUCCESS;
	}

	// ======================get() set()方法
	public Pagination getPage() {
		return page;
	}

	public void setPage(Pagination page) {
		this.page = page;
	}

	public ShareManageService getshareManageService() {
		return shareManageService;
	}

	public void setshareManageService(ShareManageService shareManageService) {
		this.shareManageService = shareManageService;
	}

	public List<ShareDto> getShareList() {
		return shareList;
	}

	public void setShareList(List<ShareDto> shareList) {
		this.shareList = shareList;
	}

	public ShareDto getShareInfo() {
		return shareInfo;
	}

	public void setShareInfo(ShareDto shareInfo) {
		this.shareInfo = shareInfo;
	}

	public ShareDto getCondition() {
		return condition;
	}

	public void setCondition(ShareDto condition) {
		this.condition = condition;
	}

	public Map<Integer, String> getTypeTabList() {
		return typeTabList;
	}

	public void setTypeTabList(Map<Integer, String> typeTabList) {
		this.typeTabList = typeTabList;
	}

}
